<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>admin/js/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>admin/test/css/icon.css">
	<script type="text/javascript" src="<%=basePath %>admin/test/js/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath %>admin/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=basePath %>admin/js/easyui-lang-zh_CN.js"></script> 
	<script>
		$(function(){
			$('#test').datagrid({
				title:'增加医院',
				iconCls:'icon-ok',
				width:1000,
				height:650,
				pageNumber:1,
				pageSize:10,
				pageList:[5,10,11,12,13,14,15,16,17,18,19,20,25,30,35,50,70,60,80,100],
                collapsible:true,
				nowrap: true,
				striped: true,
				url:'<%=basePath%>initHospital2hospitalAction',
				sortName: 'id',
				sortOrder:'desc',
				rownumbers:true,
				idField:'id',
				queryParam:{},
				singleSelect:false,
				frozenColumns:[[
                 {field:'ck',checkbox:true}
              ]],
	        columns:[[
	        {field:'id',title:'编号',width:60,sortable:true,editor:'text'},
			{field:'name',title:'医院名称',width:120,sortable:false,editor:'text'},
			{field:'code',title:'所属地区',width:100,sortable:false,editor:'text'},
		    {field:'address',title:'地址',width:150,sortable:false,editor:'text'},
		   {field:'telephone',title:'来院电话',width:100,sortable:false,editor:'text'},
		   {field:'weburl',title:'医院网址',width:100,sortable:false,editor:'text'},
		    {field:'flag',title:'是否开通web预约挂号',width:100,sortable:false,editor:'text'},
		   {field:'busline',title:'来院路线',width:220,sortable:false,editor:'text'},
			{field:'operator',title:'操作列',width:70,align:'center',
          formatter:function(value,row,index){
        if(row.editing)
        {
            var s ='<a href="javascript:void(0);" onclick="saveRow('+index+')" style="text-decoration: none;color: #800080;">保存</a>  ';
            var c ='<a href="javascript:void(0);" onclick="cancelRow('+index+')" style="text-decoration: none;color: #800080;">取消</a>';
            return s+c;
        }
        else
        {
             var e = '<img src="<%=basePath%>admin/test/css/icons/btn_edit.png" onclick="editRow('+index+')" > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
             var d = '<img src="<%=basePath%>admin/test/css/icons/btn_delete.png" onclick="delRow('+index+')" > ';
        return e+d;
        }
    }
}
				]],
				pagination:true,//分页时需要设置,下方显示分页插件
				rownumbers:true,
				toolbar:[{
             text:'增加',
             iconCls:'icon-add',
             handler:function()
             {
                 
               $('#add').show();
			$('#add').dialog({
			buttons:[{
						text:'增加',
						iconCls:'icon-save',
						handler:function()
						{
							addHospital();
						}
					},{
						text:'取消',
						handler:function()
						{
							$('#add').dialog('close');
							//$("#test").datagrid("loaded");
						}
					}]
			});
			
             }
          },'-',
          {
  			  text:'查询',
              iconCls:'icon-search',
              handler:function()
              {
                  $('#query').window('open');
              }
          },'-',
          {
                    id:'btncut',
					text:'批量删除',
					iconCls:'icon-cut',
					handler:function()
					{
						delUserSelect();
					}
          }
        ],
             onBeforeEdit:function(index,row)
             {
               row.editing = true;
               $('#test').datagrid('refreshRow',index);
               count++;
             },
        onAfterEdit:function(index,row)
        {
            row.editing = true;
            $('#test').datagrid('refreshRow',index);
            count--;
        },
        onCancelEdit:function(index,row)
        {
            row.editing = false;
            $('#test').datagrid('refreshRow',index);
            count--;
        },
		onSortColumn:function(sort,order)
		{
			alert(sort+":"+order)
		}
				
			});
		});
		/*重新加载*/
		function resize(){
			$('#test').datagrid({
				title: '新标题',
				striped: true,
				width: 650,
				loadMsg:'正在处理，请稍待。。。',
				queryParams:{
					a:'abc',
					name:'sjx'
				}
			});
		}
		/*删除提示*/
		function delUserSelect(){
			var rows = $('#test').datagrid('getSelections');
			if(rows.length>0)
			{
				del();
			}
			else
			{
			   $.messager.alert('提醒','请选择一行','info');
				return false;
			}
		}
		//确认删除
		function  del()
		{
			$.messager.confirm('确认','你确定要删除吗?',function(r)
			{
			   if (r)
			   {
			    	myAjaxDel();
			   }	
	   		});
		}
		//删除操作
		function myAjaxDel()
		{
			var ids = [];
			var rows = $('#test').datagrid('getSelections');
			for(var i=0;i<rows.length;i++)
			{
				ids.push(rows[i].id);
			}
			$.ajax({
				   type: 'post',
				   url: "delHospitalshospitalAction",
				   data: "delHospitalIds="+ids,
				   success: function(data)
				   {
				     if(data=='ok')
				     {
						$.messager.alert('提醒','删除成功','info');
						var rows2 = $('#test').datagrid('getSelections');//获取你选择的所有行
						//循环所选的行
						for(var i =0;i<rows2.length;i++)
						{
							var index2 = $('#test').datagrid('getRowIndex',rows2[i]);//获取某行的行号
							$('#test').datagrid('deleteRow',index2);	//通过行号移除该行
						}
						
					}
					if(data=='error')
					{
						$.messager.alert('提醒','删除失败','info');
					}
				  }
			});
      }
		
		/*获取选中的编号*/
		function getSelected()
		{
			var selected = $('#test').datagrid('getSelected');
			alert(selected.id+":"+selected.name);
			
		}
		/*获取所有选中的编号*/
		function getSelections()
		{
			var ids = [];
			var rows = $('#test').datagrid('getSelections');
			for(var i=0;i<rows.length;i++)
			{
				ids.push(rows[i].id);
			}
			
		}
		function myformatter(value,rec)
		{
			return 'a:'+value+'>'+rec.name;
		}
      
    //提交保存
	function updateHospital()
	{
		$('#UpdateHospitalFrom').form({
			    	success:function(data)
			    	{
			    	
			    		if(data=='ok')
			    		{
			    			$.messager.alert('后台提示', '数据更新成功', 'info');
			    			//初始化
			    			$('#dd').dialog('close');
			    			$('#test').datagrid('reload');
			    		}
						
						if(data=='error')
						{
						    $('#dd').dialog('close');
			    			$.messager.alert('后台提示', '数据更新失败', 'info');
			    		}
			    	}	
				}).submit();
	}
	 //提交增加医院信息
	function addHospital()
	{
		$('#addHospitalFrom').form({
			    	success:function(data)
			    	{
			    	
			    		if(data=='ok')
			    		{
			    			$.messager.alert('后台提示', '数据添加成功', 'info');
			    			//初始化
			    			$('#add').dialog('close');
			    			$('#test').datagrid('reload');
			    		}
						
						if(data=='error')
						{
			    			$.messager.alert('后台提示', '数据添加失败', 'info');
			    			$('#add').dialog('close');
			    		}
			    	}	
				}).submit();
	}
    /*单个删除操作*/
    function delRow(index)
    {
           var selected = $('#test').datagrid('getSelected');//获取你选择的所有行
           if(selected!=null)
           {
	             $.messager.confirm('确认','你确定要删除吗?',function(r)
				  {
					  if(r)
					  {
					      $.ajax({
								   type: 'post',
								   url: "delHospitalshospitalAction",
								   data: "delHospitalIds="+selected.id,
								   success: function(data)
								   {
								     if(data=='ok')
								     {
										$.messager.alert('提醒','删除成功','info');
										//删除所选的行
										var index2 = $('#test').datagrid('getRowIndex',selected);//获取某行的行号
										$('#test').datagrid('deleteRow',index2);	//通过行号移除该行
									}
									if(data=='error')
									{
										$.messager.alert('提醒','删除失败','info');
									}
								  }
							});
					  }
				  })
			}
			else
			{
			  $.messager.alert('后台提示', '请在要删除的行前打钩', 'info');
			  return false;
			}			
		 
    }
		/*编辑医院信息*/
		function editRow(index)
		{
           // $('#test').datagrid('beginEdit',index);
      
        var rows = $('#test').datagrid('getSelections')
		 if(rows.length==1)
		 {
			editing();			
		 }
		 else
		 {
			$.messager.alert('提醒','请选择一行','info');
			return false;
		 }
        }
function editing()
     {
    	var selected = $('#test').datagrid('getSelected');
		if (selected)
		{
			//给页面赋值
			$('#id').val(selected.id);
			$('#name').val(selected.name);
			$('#code').val(selected.code);
			$('#address').val(selected.address);
			$('#telephone').val(selected.telephone);
			$('#weburl').val(selected.weburl);
			$('#introduce').val(selected.introduce);
			$('#busline').val(selected.busline);
			$('#flag').val(selected.flag);
			$('#leve').val(selected.leve);
			$('#dd').show();
			$('#dd').dialog({
			buttons:[{
						text:'更新',
						iconCls:'icon-save',
						handler:function()
						{
							updateHospital();
						}
					},{
						text:'取消',
						handler:function()
						{
							$('#dd').dialog('close');
							//$("#test").datagrid("loaded");
						}
					}]
			});
					
		}
    }
    
    /*取消*/
    function cancelRow(index)
    {
        $('#test').datagrid('cancelEdit',index);
    }
		/*增加医院信息*/
		var count=0;
 
   
    /*查询*/
     function query()
     {
  
        var queryParams = $('#test').datagrid('options').queryParams;
        queryParams.queryType = $('#queryType').val();
        queryParams.queryValue = $('#queryValue').val();
        	$('#test').datagrid(
        	{
        	     
            	url:'<%=basePath%>queryHospitalhospitalAction'
        	});
        	$('#query').window('close');        
        
    }
   
	</script>
</head>
<body>
	<table id="test"></table>
	
	 <div id="dd" icon="icon-edit" style="display:none;padding-top:30px;width:750px;height:450px;">
  <div style="width:700px;height:auto;background:#fcfcfc;" >
  <form action="<%=basePath %>updateHospitalhospitalAction" id="UpdateHospitalFrom"  method="post">
		<table class="grid" id="uiform" >
			<tr>
				<td>
					*医院名称：
				</td>
				<td>
				<input type="hidden" id="id" name="hospital.id"/>
					<input id="name"  type="text" name="hospital.name"   class="txt03" value="" />
				</td>
				<td>
					*所属地区：
				</td>
				<td>
				<input id="code" class="easyui-combotree" url="<%=basePath %>initAreasyscodeAction" style="width:150px;"  name="hospital.syscode.name"/>
				</td>
			</tr>
			<tr>
				<td>
					*地址：
				</td>
				<td>
					<input id="address"   maxlength="20" name="hospital.address" class="txt03"  value=""  />
				</td>
					<td>
					*电话：
				</td>
				<td>
					<input id="telephone"   name="hospital.telephone"  class="txt03"  value=""  />
				</td>
			</tr>
				<tr>
				<td>
					*网站：
				</td>
				<td>
					<input id="weburl"  maxlength="20" name="hospital.weburl" class="txt03"  value=""  />
				</td>
					<td>
					*简介：
				</td>
				<td>
					<input id="introduce" name="hospital.introduce"  class="txt03"  value=""  />
				</td>
			</tr>
				<tr>
				<td>
					*是否开通web预约挂号：
				</td>
				<td>
					<input type="checkbox" id="flag" name="hospital.flag"  class="txt03"  value="" />
				</td>
					<td>
					*来院路线：
				</td>
				<td>
					<input id="busline" name="hospital.busline"  class="txt03"  value=""  />
				</td>
			</tr>
		</table>
		</form>
</div></div>
	
	<div id="query" class="easyui-window" title="查询" style="padding: 10px;width: 400px;height:120;"
    iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
        <div>
            <table>
                <tr>
                    <td>
                        <select name="select" id="queryType">
                            <option value="id">编号</option>
                            <option value="name">医院名称</option>
                            <option value="leve">医院等级</option>
                        </select>
                    </td>
                    <td><input type="text" style="background:#fcfcfc;" name="queryValue" id="queryValue"  value="" /></td>
                    <td><a class="easyui-linkbutton" iconCls="icon-search" href="javascript:void(0);" onclick="query()">查询</a></td>
                </tr>
            </table>
        </div>
    </div>
    <div id="add" icon="icon-edit" style="display:none;padding-top:30px;width:750px;height:450px;">
  <div style="width:700px;height:auto;background:#fcfcfc;" >
  <form action="<%=basePath %>addHospitalhospitalAction" id="addHospitalFrom"  method="post">
		<table class="grid" id="uiform">
			<tr>
				
				<td>
					*医院名称：
				</td>
				<td>
					<input id="name"  type="text" name="hospital.name"   class="txt03" value="" />
				</td>
				<td>
					所属地区：
				</td>
				<td>
		
				<input id="code" class="easyui-combotree" url="<%=basePath %>initAreasyscodeAction" style="width:150px;"  name="hospital.syscode.name"/>
					
				</td>
			</tr>
			<tr>
				<td>
					*医院地址：
				</td>
				<td>
					<input id="address"   maxlength="20" name="hospital.address" class="txt03"  value=""  />
				</td>
					<td>
					*医院电话：
				</td>
				<td>
					<input id="telephone"   name="hospital.telephone"  class="txt03"  value=""  />
				</td>
			</tr>
				<tr>
				<td>
					*医院网站：
				</td>
				<td>
					<input id="weburl"  maxlength="20" name="hospital.weburl" class="txt03"  value=""  />
				</td>
					<td>
					*医院简介：
				</td>
				<td>
					<input id="introduce" name="hospital.introduce"  class="txt03"  value=""  />
				</td>
			</tr>
				<tr>
				<td>
					*是否开通web预约挂号：
				</td>
				<td>
					<input type="checkbox" id="flag" name="hospital.flag"  class="txt03"  value="" />
				</td>
					<td>
					*来院路线：
				</td>
				<td>
					<input id="busline" name="hospital.busline"  class="txt03"  value=""  />
				</td>
			</tr>
		</table>
		</form>
</div></div>
</body>
</html>